package org.linlinjava.litemall.admin.web;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.service.LitemallGoodsProductService;
import org.linlinjava.litemall.db.service.LitemallGoodsService;
import org.linlinjava.litemall.db.service.LitemallOrderService;
import org.linlinjava.litemall.db.service.LitemallUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/dashboard")
public class AdminHomePageController {

    @Resource
    private LitemallUserService userService;
    @Resource
    private LitemallGoodsService goodsService;
    @Resource
    private LitemallGoodsProductService productService;
    @Resource
    private LitemallOrderService orderService;

    /**
     * 查询展示首页数据
     */
    @GetMapping("")
    public Object count(){
        Map<Object,Integer> data=new HashMap<>();

        int userTotal = userService.count();
        int goodsTotal = goodsService.count();
        int productTotal = productService.count();
        int orderTotal = orderService.count();

        data.put("userTotal",userTotal);
        data.put("goodsTotal",goodsTotal);
        data.put("productTotal",productTotal);
        data.put("orderTotal",orderTotal);

        return ResponseUtil.ok(data);
    }

}
